//
//  GetMessagesTableViewCell.m
//  PYWGetColor
//
//  Created by 杜文杰 on 2018/6/17.
//  Copyright © 2018年 dwj. All rights reserved.
//

#import "GetMessagesTableViewCell.h"
@interface GetMessagesTableViewCell()
@property (nonatomic, strong) UISwitch *swithButton;// 开关
@property (nonatomic, strong) UILabel *titleLabel; // 标题
@property (nonatomic, strong) UILabel *detailLabel; // 副标题
@property (nonatomic, assign) BOOL isOnorOff;// 开关
@end

@implementation GetMessagesTableViewCell
- (void)setDataDic:(NSDictionary *)dataDic
{
    self.titleLabel.text = dataDic[@"titleName"];
    self.detailLabel.text = dataDic[@"detailName"];
}
- (void)switchAction:(UISwitch *)sender{
    NSLog(@"开关%d",sender.on);
    self.isOnorOff = sender.on;
    if (self.switchBtnBlock) {
        self.switchBtnBlock(sender.on);
    }
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsZero;
        
        //开关
        UISwitch *swithButton = [[UISwitch alloc] init];
        swithButton.onTintColor = getColor(@"3eceb2");
        swithButton.tintColor = [UIColor grayColor];
        swithButton.on = YES;
        [swithButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:swithButton];
        __weak typeof(self)weakself = self;
        [swithButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakself.mas_right).offset(-20 / WIDTH_6S_SCALE);
            make.centerY.equalTo(weakself.mas_centerY);
        }];
        
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.detailLabel];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.mas_top).offset((50 / HEIGHT_6S_SCALE - 40 / HEIGHT_6S_SCALE) *0.5);
            make.left.equalTo(weakself.mas_left).offset(20 / WIDTH_6S_SCALE);
            make.height.mas_offset(20 / HEIGHT_6S_SCALE);
        }];
        [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakself.mas_left).offset(20 / WIDTH_6S_SCALE);
            make.top.equalTo(weakself.titleLabel.mas_bottom);
            make.height.mas_offset(20 / HEIGHT_6S_SCALE);
        }];
    }
    return self;
}
#pragma mark - init
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor = getColor(blackColor);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = DEF_FontSize_14;
        [_titleLabel sizeToFit];
        _titleLabel.text = @"接收消息";
    }
    return _titleLabel;
}
- (UILabel *)detailLabel
{
    if (!_detailLabel) {
        _detailLabel = [[UILabel alloc] init];
        _detailLabel.textColor = getColor(textColor);
        _detailLabel.textAlignment = NSTextAlignmentLeft;
        _detailLabel.numberOfLines = 0;
        _detailLabel.font = DEF_FontSize_12;
        //[_detailLabel sizeToFit];
        _detailLabel.text = @"打开后将接收发布的需求";
    }
    return _detailLabel;
}
@end
